#include<stdio.h>
int n,m,x,y,c,r1,r2,i,flag=0,lab[1000];
int getRoot(int u){
    while(lab[u]>0)u=lab[u];
    return u;
}
void Union(int x,int y){
    int k=lab[x]+lab[y];
    if(lab[x]>lab[y]){
        lab[x]=y;
        lab[y]=k;
    }else{
        lab[y]=x;
        lab[x]=k;
    }
}
void process(){
    FILE *fp=fopen("ENTRIES.INP","r");
    FILE *out=fopen("ENTRIES.OUT","w");
    fscanf(fp,"%d%d",&n,&m);
    for(i=1;i<=101;i++)lab[i]=-1;
    for(i=1;i<=m;i++){
        fscanf(fp,"%d%c%d",&x,&c,&y);
        r1=getRoot(x);
        r2=getRoot(y);
        if(c=='+'){
            if(r1!=r2)Union(r1,r2);
        }else{
            if(flag)fprintf(out,"\n");
            flag=1;
            if(r1==r2)fprintf(out,"1");
            else fprintf(out,"0");
        }   
    }
    fclose(out);
    fclose(fp);
}
int main(){
    process();
    return 0;
}  
